Skip to content

feat(privacy): enforce G13 cohort rule and cover G7, G14, G15 with tests - #21

Merged
dalpan merged 1 commit into
feature/persona-reliabilityfrom
feature/privacy-guardrails
Oct 31, 2026
Merged

dalpan merged 1 commit into
feature/persona-reliabilityfrom
feature/privacy-guardrails

Conversation

@dalpan

@dalpan dalpan commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Stacked on #20.

Problem

G13 (individual results only for the person and their trainer) and G15 (no live results in gamification) were listed as "planned enforcement" in docs/guardrails.md. Checking the endpoints:

  • GET /api/analytics/team returned member_stats (every member's average score) to any member of the organization, trainees included.
  • GET /api/risk-profile/org/{id} returned per-principle averages to a non-staff org owner even for a two-person org, where an average identifies the other person.
  • G15 held in practice (live services only write live_* collections), but nothing tested it.
  • G7 and G14 had no regression test either.

Changes

  • services/privacy.py: MIN_COHORT = 5, cohort_too_small().
  • /analytics/team: member_stats for staff only. Other members get aggregates, or {"suppressed": true} with just the member count when the org has fewer than 5 members.
  • /risk-profile/org/{id}: the same suppression for a non-staff owner when fewer than 5 members have a risk profile. Admins are unchanged.
  • server.ensure_indexes(): index creation extracted from lifespan so the G14 TTL indexes can be tested.
  • Tests:
    • tests/test_privacy_guardrails.py: G13 for both endpoints (member, small org, staff, admin), and G15. For G15, a live click, a GoPhish-reported recipient and a forwarded report leave XP, level, badges, lab results and the leaderboard unchanged.
    • tests/test_live.py: G7 (unknown objective fails pre-flight; a client-supplied system_prompt is rejected) and G14 (180-day TTL on at for live_events and live_messages).
  • Docs: the guardrails table points at the enforcing code; api.md documents the cohort rule.

The frontend does not call either endpoint, so there is no UI change.

Testing

  • pytest: 260 passed
  • ruff check / ruff format --check clean

🤖 Generated with Claude Code

G13 and G15 were documented as "planned enforcement". Checking the analytics
endpoints showed G13 was not held: GET /analytics/team returned every
member's average score to any member of the organization, trainees included.

- services/privacy.py: MIN_COHORT = 5.
- GET /analytics/team: per-member stats for staff only; other members get
  aggregates, and nothing but the member count when the org has fewer than 5.
- GET /risk-profile/org/{id}: a non-staff owner gets the same suppression
  when fewer than 5 members have a risk profile.
- G15: regression test that a live click, a GoPhish-reported recipient and a
  forwarded report leave XP, level, badges, lab results and the leaderboard
  unchanged.
- G7: tests that an unknown objective fails pre-flight and that a client
  cannot send a persona prompt.
- G14: index creation moved into server.ensure_indexes() so the 180-day TTL
  on live_events and live_messages can be tested.
- docs: guardrails table points at the enforcing code; api.md documents the
  cohort rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dalpan
dalpan merged commit 17dcd0d into feature/persona-reliability Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant